import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './libs/yidianyun.css'
import ajax from './libs/ajax.js'
import {
  XButton,
  Grid,
  GridItem,
  PopupRadio,
  Group,
  PopupHeader,
  ButtonTab,
  ButtonTabItem,
  Search,
  Datetime,
  Card,
  Cell
} from 'vux'

Vue.component('cell', Cell)
Vue.component('card', Card)
Vue.component('datetime', Datetime)
Vue.component('search', Search)
Vue.component('button-tab', ButtonTab)
Vue.component('button-tab-item', ButtonTabItem)
Vue.component('popup-header', PopupHeader)
Vue.component('grid', Grid)
Vue.component('group', Group)
Vue.component('grid-item', GridItem)
Vue.component('XButton', XButton)
Vue.component('popup-radio', PopupRadio)

Vue.config.productionTip = false
// dwr 发送后端请求
Vue.prototype.newProjectDwr = window.newProjectDwr
Vue.prototype.ajax = ajax

router.beforeEach((to, from, next) => {
  if (to.path !== '/login' && !localStorage.getItem('userName')) {
    next('/login')
  } else {
    next()
  }
})

window.vm = new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
